/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AccountStatus;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.MailStatus;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.EntryCacheDataKey;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.ldap.LdapObjectClass;
/*     */ import com.zimbra.cs.ldap.unboundid.InMemoryLdapServer;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.BinaryLdapData.Content;
/*     */ import java.util.Arrays;
/*     */ import java.util.Collection;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Locale;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvEntry
/*     */   extends LdapTest
/*     */ {
/*  48 */   private static final String DOMAIN_NAME = "中文." + baseDomainName();
/*     */   
/*     */   private static final String ACCTNAME_LOCAL_PART = "test-ldap-prov-entry";
/*  51 */   private static final BinaryLdapData.Content binaryData = BinaryLdapData.Content.generateContent(1024);
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static Cos cos;
/*     */   private static Server server;
/*     */   private static Account account;
/*     */   private static Account entry;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init() throws Exception
/*     */   {
/*  63 */     provUtil = new LdapProvTestUtil();
/*  64 */     prov = provUtil.getProv();
/*     */     
/*  66 */     domain = provUtil.createDomain(DOMAIN_NAME, new HashMap());
/*  67 */     cos = prov.get(Key.CosBy.name, "default");
/*  68 */     server = prov.getLocalServer();
/*     */     
/*  70 */     BinaryLdapData.Content content = BinaryLdapData.Content.generateContent(1024);
/*  71 */     Map<String, Object> attrs = new HashMap();
/*  72 */     attrs.put("userSMIMECertificate", binaryData.getString());
/*     */     
/*  74 */     account = provUtil.createAccount("test-ldap-prov-entry", domain, attrs);
/*  75 */     entry = account;
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  80 */     Cleanup.deleteAll(new String[] { DOMAIN_NAME });
/*     */   }
/*     */   
/*     */   private void verifyAccountObjectClass(Collection<String> values) {
/*  84 */     if (InMemoryLdapServer.isOn())
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  96 */       Assert.assertEquals(7L, values.size());
/*     */ 
/*     */ 
/*     */     }
/*     */     else
/*     */     {
/*     */ 
/* 103 */       Assert.assertEquals(3L, values.size());
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getLabel() throws Exception {
/* 109 */     Assert.assertEquals(account.getName(), entry.getLabel());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrDefault() throws Exception {
/* 114 */     String ATTRNAME_NO_DEFAULT = "zimbraId";
/* 115 */     String ATTRNAME_HAS_DEFAULT = "zimbraFeatureContactsEnabled";
/*     */     
/* 117 */     Assert.assertNull(entry.getAttrDefault(ATTRNAME_NO_DEFAULT));
/* 118 */     Assert.assertEquals(cos.getAttr(ATTRNAME_HAS_DEFAULT), entry.getAttrDefault(ATTRNAME_HAS_DEFAULT));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttr() throws Exception {
/* 123 */     Assert.assertEquals(account.getId(), entry.getAttr("zimbraId"));
/* 124 */     Assert.assertEquals(account.getName(), entry.getAttr("mail"));
/* 125 */     Assert.assertEquals(account.getName(), entry.getAttr("zimbraMailDeliveryAddress"));
/* 126 */     Assert.assertEquals("test-ldap-prov-entry", entry.getAttr("uid"));
/* 127 */     Assert.assertEquals(server.getName(), entry.getAttr("zimbraMailHost"));
/* 128 */     Assert.assertEquals(ZAttrProvisioning.AccountStatus.active.name(), entry.getAttr("zimbraAccountStatus"));
/* 129 */     Assert.assertEquals(ZAttrProvisioning.MailStatus.enabled.name(), entry.getAttr("zimbraMailStatus"));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrWithWithoutDefaults() throws Exception {
/* 134 */     String ATTR = "zimbraFeatureMailEnabled";
/*     */     
/*     */ 
/* 137 */     String value = entry.getAttr(ATTR, true);
/* 138 */     Assert.assertEquals("TRUE", value);
/*     */     
/*     */ 
/* 141 */     value = entry.getAttr(ATTR, false);
/* 142 */     Assert.assertNull(value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrWithProvidedDefaultValue() throws Exception {
/* 147 */     String ATTR = "zimbraACE";
/* 148 */     String DEFAULT_VALUE_PROVIDED = "blah";
/*     */     
/*     */ 
/* 151 */     String value = entry.getAttr(ATTR, false);
/* 152 */     Assert.assertNull(value);
/*     */     
/* 154 */     value = entry.getAttr(ATTR, DEFAULT_VALUE_PROVIDED);
/* 155 */     Assert.assertEquals(DEFAULT_VALUE_PROVIDED, value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrs() throws Exception {
/* 160 */     Map<String, Object> attrs = entry.getAttrs();
/*     */     
/* 162 */     Object value = attrs.get("objectClass");
/* 163 */     Assert.assertTrue(value instanceof String[]);
/* 164 */     List<String> values = Arrays.asList((String[])value);
/*     */     
/* 166 */     verifyAccountObjectClass(values);
/* 167 */     Assert.assertTrue(values.contains(LdapObjectClass.ZIMBRA_DEFAULT_PERSON_OC));
/* 168 */     Assert.assertTrue(values.contains(AttributeClass.account.getOCName()));
/* 169 */     Assert.assertTrue(values.contains("amavisAccount"));
/*     */     
/* 171 */     value = attrs.get("zimbraId");
/* 172 */     Assert.assertTrue(value instanceof String);
/* 173 */     Assert.assertEquals(entry.getId(), (String)value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAttrsWithWithoutDefaults() throws Exception {
/* 178 */     String ATTR = "zimbraFeatureMailEnabled";
/*     */     
/*     */ 
/* 181 */     Map<String, Object> attrs = entry.getAttrs(true);
/* 182 */     Object value = attrs.get(ATTR);
/* 183 */     Assert.assertTrue(value instanceof String);
/* 184 */     Assert.assertEquals("TRUE", value);
/*     */     
/*     */ 
/* 187 */     attrs = entry.getAttrs(false);
/* 188 */     value = attrs.get(ATTR);
/* 189 */     Assert.assertNull(value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getUnicodeAttrs() throws Exception {
/* 194 */     Map<String, Object> attrs = entry.getUnicodeAttrs();
/*     */     
/* 196 */     Object value = attrs.get("zimbraMailDeliveryAddress");
/* 197 */     Assert.assertTrue(value instanceof String);
/* 198 */     String[] parts = ((String)value).split("@");
/* 199 */     Assert.assertEquals("test-ldap-prov-entry", parts[0]);
/* 200 */     Assert.assertEquals(DOMAIN_NAME, parts[1]);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getUnicodeAttrsWithWithoutDefaults() throws Exception
/*     */   {
/* 206 */     Map<String, Object> attrs = entry.getUnicodeAttrs(true);
/*     */     
/*     */ 
/*     */ 
/* 210 */     attrs = entry.getUnicodeAttrs(false);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getBooleanAttr() throws Exception {
/* 215 */     String ATTR = "zimbraFeatureMailEnabled";
/*     */     
/* 217 */     boolean value = entry.getBooleanAttr(ATTR, false);
/* 218 */     Assert.assertTrue(value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getBinaryAttr() throws Exception {
/* 223 */     byte[] value = entry.getBinaryAttr("userSMIMECertificate");
/* 224 */     Assert.assertTrue(binaryData.equals(value));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getGeneralizedTimeAttr() throws Exception {
/* 229 */     String ATTR = "zimbraCreateTimestamp";
/*     */     
/* 231 */     Date now = new Date();
/* 232 */     Date value = entry.getGeneralizedTimeAttr(ATTR, null);
/*     */     
/*     */ 
/* 235 */     Assert.assertTrue(now.getTime() - value.getTime() < 60000L);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getIntAttr() throws Exception {
/* 240 */     String ATTR = "zimbraContactAutoCompleteMaxResults";
/*     */     
/* 242 */     int value = entry.getIntAttr(ATTR, 0);
/* 243 */     Assert.assertEquals(20L, value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getLocale() throws Exception
/*     */   {
/* 249 */     Locale locale = entry.getLocale();
/*     */     
/* 251 */     Assert.assertEquals(Locale.US, locale);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getLongAttr() throws Exception
/*     */   {}
/*     */   
/*     */   @Test
/*     */   public void getMultiAttr() throws Exception
/*     */   {
/* 261 */     String[] value = entry.getMultiAttr("objectClass");
/*     */     
/* 263 */     Assert.assertTrue(value instanceof String[]);
/* 264 */     List<String> values = Arrays.asList((String[])value);
/* 265 */     verifyAccountObjectClass(values);
/* 266 */     Assert.assertTrue(values.contains(LdapObjectClass.ZIMBRA_DEFAULT_PERSON_OC));
/* 267 */     Assert.assertTrue(values.contains(AttributeClass.account.getOCName()));
/* 268 */     Assert.assertTrue(values.contains("amavisAccount"));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMultiBinaryAttr() throws Exception {
/* 273 */     List<byte[]> value = entry.getMultiBinaryAttr("userSMIMECertificate");
/* 274 */     Assert.assertEquals(1L, value.size());
/* 275 */     Assert.assertTrue(binaryData.equals((byte[])value.get(0)));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getUnicodeMultiAttr() throws Exception {
/* 280 */     String[] value = entry.getUnicodeMultiAttr("zimbraMailDeliveryAddress");
/* 281 */     Assert.assertEquals(1L, value.length);
/* 282 */     Assert.assertEquals(TestUtil.getAddress("test-ldap-prov-entry", DOMAIN_NAME), value[0]);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMultiAttrWithWithoutDefaults() throws Exception {
/* 287 */     String ATTR = "zimbraFeatureMailEnabled";
/*     */     
/*     */ 
/* 290 */     String[] value = entry.getMultiAttr(ATTR, true);
/* 291 */     Assert.assertEquals(1L, value.length);
/* 292 */     Assert.assertEquals("TRUE", value[0]);
/*     */     
/*     */ 
/* 295 */     value = entry.getMultiAttr(ATTR, false);
/* 296 */     Assert.assertEquals(0L, value.length);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMultiBinaryAttrWithWithoutDefaults() throws Exception
/*     */   {}
/*     */   
/*     */   @Test
/*     */   public void getMultiAttrSet() throws Exception
/*     */   {
/* 306 */     String ATTR = "objectClass";
/*     */     
/* 308 */     Set<String> values = entry.getMultiAttrSet(ATTR);
/* 309 */     verifyAccountObjectClass(values);
/* 310 */     Assert.assertTrue(values.contains(LdapObjectClass.ZIMBRA_DEFAULT_PERSON_OC));
/* 311 */     Assert.assertTrue(values.contains(AttributeClass.account.getOCName()));
/* 312 */     Assert.assertTrue(values.contains("amavisAccount"));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMultiBinaryAttrSet() throws Exception {
/* 317 */     Set<byte[]> value = entry.getMultiBinaryAttrSet("userSMIMECertificate");
/* 318 */     Assert.assertEquals(1L, value.size());
/* 319 */     for (byte[] val : value) {
/* 320 */       Assert.assertTrue(binaryData.equals(val));
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getTimeInterval() throws Exception {
/* 326 */     String ATTR = "zimbraMailTrashLifetime";
/* 327 */     long value = entry.getTimeInterval(ATTR, 0L);
/* 328 */     long expected = 2592000000L;
/* 329 */     Assert.assertEquals(expected, value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getTimeIntervalSecs() throws Exception {
/* 334 */     String ATTR = "zimbraMailTrashLifetime";
/* 335 */     long value = entry.getTimeIntervalSecs(ATTR, 0L);
/* 336 */     long expected = 2592000L;
/* 337 */     Assert.assertEquals(expected, value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void setCachedDataString() throws Exception {
/* 342 */     String KEY = EntryCacheDataKey.PERMISSION.name();
/* 343 */     String DATA = "123";
/* 344 */     entry.setCachedData(KEY, DATA);
/* 345 */     Object dataCached = entry.getCachedData(KEY);
/* 346 */     Assert.assertEquals(DATA, dataCached);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void setCachedData() throws Exception {
/* 351 */     EntryCacheDataKey KEY = EntryCacheDataKey.PERMISSION;
/* 352 */     String DATA = "abc";
/* 353 */     entry.setCachedData(KEY, DATA);
/* 354 */     Object dataCached = entry.getCachedData(KEY);
/* 355 */     Assert.assertEquals(DATA, dataCached);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getCachedDataString()
/*     */     throws Exception
/*     */   {}
/*     */   
/*     */   @Test
/*     */   public void getCachedData()
/*     */     throws Exception
/*     */   {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvEntry.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */